package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.SiteInfo;
import com.ruoyi.system.mapper.SiteInfoMapper;
import com.ruoyi.system.service.SiteInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SiteInfoServiceImpl implements SiteInfoService {
    @Autowired
    private SiteInfoMapper siteInfoMapper;
    @Override
    public SiteInfo selectByPrimaryKey(Long id){
        // 1. 查询站点信息
        SiteInfo siteInfo = siteInfoMapper.selectByPrimaryKey(id);

        // 2. 如果站点信息不存在，直接返回 null
        if (siteInfo == null) {
            return null;
        }

        // 3. 获取关联的用户信息
        SysUser sysuser = siteInfo.getSysuser();

        // 4. 检查用户角色是否为 101
        if (sysuser != null && sysuser.getRoleId() != null && sysuser.getRoleId() == 101) {
            return siteInfo; // 符合条件，返回数据
        } else {
            return null; // 不符合条件，返回 null
            // 或者抛出异常：
            // throw new RuntimeException("无权访问该站点信息");
        }
    }
//        return siteInfoMapper.selectByPrimaryKey(id);
    @Override
    public int updateSiteInfo(SiteInfo record){
        return siteInfoMapper.updateSiteInfo(record);
    }
    }

